// pages/exchange/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showPayPwdInput: false, //是否展示密码输入层
    pwdVal: '', //输入的密码
    payFocus: true, //文本框焦点
    scop:0,
    userid:'',
    value:'',
    values:'',
    valuess:'',
    valuesss:'',
    userid:'',
    Loadingtime: '',
    getname:"",
    radio:'',
    isradio:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      scop: (wx.getStorageSync('loginuser')).integral,
      userid:wx.getStorageSync('userId')
    })
  },
  onChange(event) {
    this.setData({
      value: event.detail.value
    })
    console.log(this.data.value);
  },
  onChanges(event) {
    this.setData({
      values: event.detail.value
    })
    console.log(this.data.values);
  },
  onChangess(event) {
    console.log(event);
    this.setData({
      valuess: event.detail
    })
    console.log(this.data.valuess);
    if(this.data.valuess){
      wx.request({
        url: app.globalData.url+'/zkxj/user/getNameByUserId',
        data: {
          "userId": this.data.valuess
        },
        method: 'GET',
        header: {
          'content-type': 'application/json',
            'token':wx.getStorageSync('token')
        },
        success: (res) => {
          console.log(res.data);
          if(res.data.code==0){
           this.setData({
             getname:res.data.name
           })
          }
          console.log(this.data.getname);
         
  
        }
      })
    }
  },
  //点击选择确认
  onChangeradio(event){
    console.log(!this.data.radio);
    this.setData({
      radio: !this.data.radio,
      isradio:!this.data.radio
    });
  },

  onChangesss(event) {
    this.setData({
      valuesss: event.detail.value
    })
    console.log(this.data.valuesss);
  },
  handlecheck(){
    if(this.data.radio){

      if(this.data.value&&this.data.valuess&&this.data.valuess){
        wx.request({
          url: app.globalData.url+'/zkxj/user/xjjjf/transfer',
          data: {
            "amount":JSON.parse(this.data.value),
            "curUserId":JSON.parse(this.data.userid),
            "payPass":this.data.valuesss,
            "remark": "",
            "userId":JSON.parse(this.data.valuess),
          },
          method: 'POST',
          header: {
            'content-type': 'application/json',
              'token':wx.getStorageSync('token')
          },
          success: (res) => {
            console.log(res.data);
            if (res.data.code == 0) {
              wx.showToast({
                title: '转账成功！',
                icon: 'success',
                duration: 1000,
                mask: true
              })
              this.setData({
                Loadingtime: setInterval(function () {
                  wx.switchTab({
                    url: '/pages/mycenter/index',
                  })
                }, 2000)
              })
              
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'error',
                duration: 1000,
                mask: true
              })
            }
    
          }
        })
      }else{
        wx.showToast({
          title: '请完整填写信息！',
          icon: 'error',
          duration: 1000,
          mask: true
        })
      }
    }else{
      wx.showToast({
        title: '请确认转账信息！',
        icon: 'error',
        duration: 1000,
        mask: true
      })
    }
  },
 
  

 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 // 关闭当前页面时取消定时器
 clearInterval(this.data.Loadingtime);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 // 关闭当前页面时取消定时器
 clearInterval(this.data.Loadingtime);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
// 关闭当前页面时取消定时器
clearInterval(this.data.Loadingtime);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})